package com.sci.web.controller.admin.v2;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.plugin.activerecord.Page;
import com.sci.config.MyConstants;
import com.sci.web.business.admin.SysEnumsBusiness;
import com.sci.web.controller.BaseController;
import com.sci.web.model.dto.PageDto;
import com.sci.web.model.genmodel.SysEnums;
import com.sci.web.model.genmodel.User;
import com.sci.web.util.DateUtil;
import com.sci.web.util.GetWaterId;
import com.sci.web.util.StringUtil;

public class SysEnumsController extends BaseController {
	
	
	public SysEnumsBusiness  sysEnumsBusiness= new SysEnumsBusiness();
	
	
	
	
	/**  
	* @Title: getSysEnumPageInate  
	* @Description: 分页展示参数   
	* @returnType void      
	* @author LiuFei
	* @date 下午7:01:58
	* @throws  
	*/
	public void getSysEnumPageInate(){
		PageDto page = new PageDto();
		Integer draw = getParaToInt("draw");
		Integer start = getParaToInt("start");
		Integer length = getParaToInt("length");
		String searchVal = getPara("search[value]");
		 //Page<BlogContent> blogPageInit = blogContentService.getBlogPageInit(user.getUserNo(), searchVal, (start/length)+1 , length);
		Integer pageSize = 15;
		Page<SysEnums> sysEnumsPageInate = sysEnumsBusiness.getSysEnumsPageInate(1, pageSize);
		page.setDraw(draw);
		page.setRecordsTotal(sysEnumsPageInate.getTotalRow());
		page.setRecordsFiltered(sysEnumsPageInate.getTotalRow());
		page.setData(sysEnumsPageInate.getList());
		renderJson(page);
	}
	
	
	/**  
	* @Title: getSysEnumsInfo  
	* @Description: 查看具体参数
	* @returnType void      
	* @author LiuFei
	* @date 下午7:02:11
	* @throws  
	*/
	public void getSysEnumsInfo(){
		String id = getPara("id");
		SysEnums sysEnumsById = sysEnumsBusiness.getSysEnumsById(id);
		if(sysEnumsById!=null){
			success(sysEnumsById);
		}else{
			error("error");
		}
	}
	
	
	/**  
	* @Title: insertSysEnums  
	* @Description: 新增参数 
	* @returnType void      
	* @author LiuFei
	* @date 下午7:02:22
	* @throws  
	*/
	public void insertSysEnums(){
		String parameter = super.getParameter("reqStr");
		User user = super.getSessionByUser();
		
		if(parameter!=null && user!=null){
			Map<String , String> parseObject = (Map<String , String>)JSONObject.parseObject(parameter , Map.class);
			SysEnums enums = new SysEnums();
			enums.setSerialId(GetWaterId.getWaterId());
			enums.setMainKey(parseObject.get("mainKey"));
			enums.setEKeyDesc(parseObject.get("eKeyDesc"));
			enums.setEKey(parseObject.get("eKey"));
			enums.setEValue(parseObject.get("eValue"));
			String currDatatTime = DateUtil.getCurrDatatTime();
			enums.setCreateTime(currDatatTime);
			enums.setUpdateTime(currDatatTime);
			enums.setIsDelete("0");
			enums.setOperatorNo(user.getUserNo());
			enums.setOperatorName(user.getUserName());
			enums.save();
			success();
		}else{
			error("");
		}
	}

	
	
	public void updateSysEnums(){
		String reqStr = super.getParameter("reqStr");
		User user = super.getSessionByUser();
		if(user!=null && StringUtil.isNotEmpty(reqStr)){
			Map<String , String> parseObject = (Map<String , String>)JSONObject.parseObject(reqStr , Map.class);
			String id = parseObject.get("serialId");
			SysEnums enums = sysEnumsBusiness.getSysEnumsById(id);
			enums.setMainKey(parseObject.get("mainKey"));
			enums.setEKeyDesc(parseObject.get("eKeyDesc"));
			enums.setEKey(parseObject.get("eKey"));
			enums.setEValue(parseObject.get("eValue"));
			enums.update();
			success();
		}else{
			error("");
			
		}
	}
	
	
	
	public void refreshSysEnums(){
		User user = super.getSessionByUser();
		if(user!=null ){
			List<SysEnums> sysEnumsAll = sysEnumsBusiness.getSysEnumsAll();
			MyConstants.enumList = sysEnumsAll;
			MyConstants.log.info("====>刷新之后Size:"+MyConstants.enumList.size());
			success();
		}else{
			error("");
		}
	}
}
